from boruta import BorutaPy


def boruta_test(estimator, x, y,  alpha=0.05, max_iter=100, perc=100,
	n_estimators='auto', two_step=True, verbose=0):
	"""
	params: https://github.com/scikit-learn-contrib/boruta_py
	"""
	# 设置 Boruta 特征选择的参数
	feat_selector = BorutaPy(
		estimator=estimator, alpha=alpha, max_iter=max_iter, perc=perc,
		n_estimators=n_estimators, two_step=two_step, verbose=verbose)

	# 特征筛选
	feat_selector.fit(x, y)

	# 通过测试的特征数量
	print('通过测试的特征数量: ', feat_selector.n_features_)

	# 特征是否通过-bool value list
	pass_bool = feat_selector.support_

	# 查看选择的特征的rank
	rank = feat_selector.ranking_

	# 用 transform() 过滤掉数据x不相关的特征
	x_filtered = feat_selector.transform(x)
	return x_filtered, feat_selector.n_features_, pass_bool, rank

